<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>自定义指令</title>
</head>

<body>
  <div id="app">
    <input type="text" v-focus>
    <input type="text" v-color="msg">
  </div>
  <script src="../js/vue.js"></script>
  <script>
    /* 
      两种自定义指令方式:bind,inserted
      bind是在dom树绘制前调用，inserted在dom树绘制后调用
    */
    Vue.directive("focus", {
      inserted: (el) => {
        //el表示指令所绑定的元素 
        el.focus();
      }
    });
    Vue.directive("color", {
      bind: (el, binding) => {
        // console.log(binding.value);
        // el.style.backgroundColor = binding.value.color;
        el.style.backgroundColor = binding.value;
      }
    });
    const vm = new Vue({
      "el": "#app",
      "data": {
        /* "msg": {
          "color": "blue"
        } */
        "msg": "red"
      },
      "methods": {

      }
    });
  </script>
</body>

</html>